<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/common/tags.jsp"%>

<aos:html title="产品详情管理" base="http" lib="ext">
<aos:body>
</aos:body>
</aos:html>


<aos:onready>
	<aos:viewport layout="border">
		<aos:formpanel id="_f_query" layout="column" labelWidth="70"
			header="false" region="north" border="false">
			<aos:docked forceBoder="0 0 1 0">
				<aos:dockeditem xtype="tbtext" text="查询条件" />
			</aos:docked>
			<aos:textfield name="product_name" fieldLabel="产品名称"   columnWidth="0.15" />
			<aos:textfield name="product_type" fieldLabel="产品类型"   columnWidth="0.15" />
			<aos:combobox name="catalogy_id" fieldLabel="产品大类"  dicField="catalogy_type_"  columnWidth="0.18"/>
			<aos:combobox name="type_id" fieldLabel="产品小类"  dicField="product_type_" columnWidth="0.25" />
			<aos:combobox name="is_spe" fieldLabel="是否特价"  dicField="is_" columnWidth="0.1"/>
			<aos:combobox name="is_rec" fieldLabel="是否推荐"  dicField="is_" columnWidth="0.1"/>
			<aos:combobox name="is_valid" fieldLabel="是否有效"  dicField="is_" columnWidth="0.1"/>
			<aos:combobox name="is_parent" fieldLabel="是否父产品"  dicField="is_" columnWidth="0.1"/>
			<aos:docked dock="bottom" ui="footer" margin="0 0 8 0">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem xtype="button" text="查询" onclick="_g_product_query" icon="query.png" />
				<aos:dockeditem xtype="button" text="重置" onclick="AOS.reset(_f_query);" icon="refresh.png" />
				<aos:dockeditem xtype="tbfill" />
			</aos:docked>
		</aos:formpanel>

		<aos:gridpanel id="_g_product" url="productService.list" onrender="_g_product_query" region="center" onitemclick="fn_g_product_click" minHeight="200">
			<aos:docked forceBoder="1 0 1 0">
				<aos:dockeditem xtype="tbtext" text="产品信息" />
			</aos:docked>
			<aos:column type="rowno" />
			<aos:column header="流水号id" dataIndex="id" hidden="true" />
			<aos:column header="父产品id" dataIndex="parent_id" hidden="true"/>
			<aos:column header="产品名称" dataIndex="product_name"/>
			<aos:column header="产品类型" dataIndex="product_type" hidden="true"/>
			<aos:column header="产品主图" dataIndex="main_url" hidden="true"/>
			<aos:column header="折后价" dataIndex="discount_price" type="number" />
			<aos:column header="原价" dataIndex="full_price" type="number" hidden="true"/>
			<aos:column header="排序" dataIndex="sort"/>
			<aos:column header="产品描述" dataIndex="discription" hidden="true"/>
			<aos:column header="产品大类" dataIndex="catalogy_id" rendererField="catalogy_type_"/>
			<aos:column header="产品小类" dataIndex="type_id" rendererField="product_type_"/>
			<aos:column header="是否特殊" dataIndex="is_spe" rendererField="is_"/>
			<aos:column header="是否推荐" dataIndex="is_rec" rendererField="is_"/>
			<aos:column header="是否有效" dataIndex="is_valid" rendererField="is_"/>
			<aos:column header="创建时间" dataIndex="create_date" type="date"	format="Y-m-d H:i:s"/>
			<aos:column header="修改时间" dataIndex="modify_date" type="date"	format="Y-m-d H:i:s"/>
			<aos:column header="添加参数" rendererFn="fn_button_param_add" align="center" />
			<aos:column header="添加faq" rendererFn="fn_button_faq_add" align="center" />
			<aos:column header="添加图片" rendererFn="fn_button_img_add" align="center" />
		</aos:gridpanel>
        
       
	    <aos:panel region="south" maxHeight="300" >
	     <aos:tabpanel id="_tabpanel" region="center" activeTab="0" bodyBorder="0 0 0 0" tabBarHeight="30">
	      <aos:tab title="参数信息" id="_tab_params">
	    	<aos:gridpanel id="_g_params"  region="center" url="productDetailService.queryParamsList" onrender="_g_params_query">
			 <aos:docked forceBoder="1 0 1 0">
				<aos:dockeditem xtype="tbtext" text="产品详情" />
			 </aos:docked>
			 <aos:column type="rowno" />
			 <aos:column header="流水号id" dataIndex="id" hidden="true" />
			 <aos:column header="参数key" dataIndex="param_key" />
			 <aos:column header="参数value" dataIndex="param_value" />
			 <aos:column header="排序" dataIndex="sort"/>
			 <aos:column header="是否有效" dataIndex="is_valid" rendererField="is_"/>
			 <aos:column header="编辑" rendererFn="fn_button_param_edit" align="center" />
             <aos:column header="删除" rendererFn="fn_button_param_del" align="center" />
			</aos:gridpanel>
		  </aos:tab>
		  <aos:tab title="FAQ" id="_tab_faq">
	    	<aos:gridpanel id="_g_faq"  region="center" url="productDetailService.queryFaqList" onrender="_g_faq_query">
			 <aos:docked forceBoder="1 0 1 0">
				<aos:dockeditem xtype="tbtext" text="产品详情" />
			 </aos:docked>
			 <aos:column type="rowno" />
			 <aos:column header="流水号id" dataIndex="id" hidden="true" />
			 <aos:column header="提问" dataIndex="question" />
			 <aos:column header="答案" dataIndex="answer" />
			 <aos:column header="排序" dataIndex="sort"/>
			 <aos:column header="是否有效" dataIndex="is_valid" rendererField="is_"/>
			 <aos:column header="编辑" rendererFn="fn_button_faq_edit" align="center" />
             <aos:column header="删除" rendererFn="fn_button_faq_del" align="center" />
   			</aos:gridpanel>
		  </aos:tab>
		  <aos:tab title="图片" id="_tab_img">
	    	<aos:gridpanel id="_g_img"  region="center" url="productDetailService.queryImgList" onrender="_g_img_query">
			 <aos:docked forceBoder="1 0 1 0">
				<aos:dockeditem xtype="tbtext" text="产品详情" />
			 </aos:docked>
			 <aos:column type="rowno" />
			 <aos:column header="流水号id" dataIndex="id" hidden="true" />
			 <aos:column header="图片url" dataIndex="pic_url" />
			 <aos:column header="排序" dataIndex="sort"/>
			 <aos:column header="是否有效" dataIndex="is_valid" rendererField="is_"/>
			 <aos:column header="编辑" rendererFn="fn_button_img_edit" align="center" />
             <aos:column header="删除" rendererFn="fn_button_img_del" align="center" />
   			</aos:gridpanel>
		  </aos:tab>	
		 </aos:tabpanel>	
		</aos:panel>


        <aos:window id="_w_query" title="查询条件" onshow="_w_query_onshow">
			<aos:formpanel id="_f_pf_query" width="400" layout="anchor" labelWidth="70">
				<aos:textfield name="product_id" fieldLabel="产品id"  />
			</aos:formpanel>
		</aos:window>



         <aos:window id="_w_param" title="参数编辑"	onshow="_w_param_onshow">
			<aos:formpanel id="_f_param" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="id" fieldLabel="流水号id"  readOnly="true" />
				<aos:textfield name="product_id" fieldLabel="产品id"  readOnly="true"/>
				<aos:textfield name="param_key" fieldLabel="参数key"  />
				<aos:textfield name="param_value" fieldLabel="参数value"  />
				<aos:textfield name="sort" fieldLabel="排序"	 />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_"/>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="updateParam()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_param.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>

         <aos:window id="_w_faq" title="问答编辑"	onshow="_w_faq_onshow">
			<aos:formpanel id="_f_faq" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="id" fieldLabel="流水号id"  readOnly="true" />
				<aos:textfield name="product_id" fieldLabel="产品id"  readOnly="true"/>
				<aos:textfield name="question" fieldLabel="参数key"  />
				<aos:htmleditor name="answer" fieldLabel="参数value"  />
				<aos:textfield name="sort" fieldLabel="排序"	 />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_"/>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="updateFaq()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_faq.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
		
		
		<aos:window id="_w_img" title="小图编辑"	onshow="_w_img_onshow">
			<aos:formpanel id="_f_img" width="400" layout="anchor"	labelWidth="70">
			    <aos:textfield name="id" fieldLabel="流水号id"  readOnly="true" />
			    <aos:textfield name="product_id" fieldLabel="产品id"  readOnly="true"/>
				<aos:textfield name="pic_url" fieldLabel="图片链接"   allowBlank="false"/>
				<aos:numberfield name="sort"  fieldLabel="排序"  allowBlank="false" />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_"/>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="updateImg()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_img.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
		
		
		
		
		
		
		<aos:window id="_w_param_add" title="参数添加"	onshow="_w_param_add_onshow">
			<aos:formpanel id="_f_param_add" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="product_id" fieldLabel="产品id"  readOnly="true"/>
				<aos:textfield name="param_key" fieldLabel="参数key"  />
				<aos:textfield name="param_value" fieldLabel="参数value"  />
				<aos:textfield name="sort" fieldLabel="排序"	 />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="addParam()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_param_add.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
		
        <aos:window id="_w_faq_add" title="问答添加"	onshow="_w_faq_add_onshow">
			<aos:formpanel id="_f_faq_add" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="product_id" fieldLabel="产品id"  readOnly="true"/>
				<aos:textfield name="question" fieldLabel="问题"  />
				<aos:htmleditor name="answer"   fieldLabel="回答"  />
				<aos:textfield name="sort"     fieldLabel="排序"	 />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="addFaq()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_faq_add.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
		
		
		<aos:window id="_w_img_add" title="图片添加"	onshow="_w_img_add_onshow">
			<aos:formpanel id="_f_img_add" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="product_id" fieldLabel="产品id"  readOnly="true"/>
				<aos:formpanel id="pic_add_">
						<aos:filefield name="uploadPic" id="uploadPic" star="true"	emptyText="请上传图片..." />
						<aos:dockeditem text="上传图片" icon="add2.png" onclick="do_upload('_f_img_add.pic_url')" />
			    </aos:formpanel>
				<aos:textfield name="pic_url" fieldLabel="图片链接"   allowBlank="false"/>
				<aos:numberfield name="sort"  fieldLabel="排序"  allowBlank="false" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="addImg()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_img_add.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
		

	</aos:viewport>

	<script type="text/javascript">
		//加载表格数据
		function _g_product_query() {
			var params = AOS.getValue('_f_query');
			_g_product_store.getProxy().extraParams = params;
			_g_product_store.loadPage(1);
		}
		//
	    function _g_params_query() {
	    	var params = AOS.getValue('_f_pf_query');
	    	_g_params_store.getProxy().extraParams = params;
	    	_g_params_store.loadPage(1);
	    	
	    }
		
	    function _g_faq_query() {
	    	var params = AOS.getValue('_f_pf_query');
	    	_g_faq_store.getProxy().extraParams = params;
	    	_g_faq_store.loadPage(1);
	    	
	    }
		
	    function _g_img_query() {
	    	var params = AOS.getValue('_f_pf_query');
	    	_g_img_store.getProxy().extraParams = params;
	    	_g_img_store.loadPage(1);
	    	
	    }
	    
	    
	    
	    
	    
		//表格单击事件
		function fn_g_product_click(obj, record) {
			AOS.setValue('_f_pf_query.product_id', record.data.id);
			 _g_params_query();
			 _g_faq_query();
			 _g_img_query();
		}
	
		
		
		//窗口弹出事件监听
		function _w_param_onshow() {
			var record = AOS.selectone(_g_params);
            AOS.ajax({
            	params : {
            		id: record.data.id
            	},
                url: 'productDetailService.getParam',
                ok: function (data) {
                	_f_param.form.setValues(data);
                }
            });
		}
		
		function _w_faq_onshow() {
			var record = AOS.selectone(_g_faq);
            AOS.ajax({
            	params : {
            		id: record.data.id
            	},
                url: 'productDetailService.getFaq',
                ok: function (data) {
                	_f_faq.form.setValues(data);
                }
            });
		}
		
		function _w_img_onshow() {
			var record = AOS.selectone(_g_img);
            AOS.ajax({
            	params : {
            		id: record.data.id
            	},
                url: 'productDetailService.getImg',
                ok: function (data) {
                	_f_img.form.setValues(data);
                }
            });
		}
		
		//更新产品
		function updateParam() {
			AOS.ajax({
				forms : _f_param,
                url: 'productDetailService.updateParam',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_params_store.reload();
					_w_param.hide();
                }
            });
		}
		
		function updateFaq() {
			AOS.ajax({
				forms : _f_faq,
                url: 'productDetailService.updateFaq',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_faq_store.reload();
					_w_faq.hide();
                }
            });
		}
		
		
		function updateImg() {
			AOS.ajax({
				forms : _f_img,
                url: 'productDetailService.updateImg',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_img_store.reload();
					_w_img.hide();
                }
            });
		}
		
		
		//添加产品
		function addParam() {
			AOS.ajax({
				forms : _f_param_add,
                url: 'productDetailService.addParam',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_params_store.reload();
     				 Ext.getCmp('_f_param_add').getForm().reset();
					_w_param_add.hide();
                }
            });
		}
		
		function addFaq() {
			AOS.ajax({
				forms : _f_faq_add,
                url: 'productDetailService.addFaq',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_faq_store.reload();
					 Ext.getCmp('_f_faq_add').getForm().reset();
					_w_faq_add.hide();
                }
            });
		}
		
		
		function addImg() {
			AOS.ajax({
				forms : _f_img_add,
                url: 'productDetailService.addImg',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_img_store.reload();
					 Ext.getCmp('_f_img_add').getForm().reset();
					_w_img_add.hide();
                }
            });
		}
		
		
		
		
		
		//删除
		function deleteParam() {
			AOS.ajax({
				forms : _f_param_add,
                url: 'productDetailService.deleteParam',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_params_store.reload();
     				 Ext.getCmp('_f_param_add').getForm().reset();
					_w_param_add.hide();
                }
            });
		}
		
		function deleteFaq() {
			AOS.ajax({
				forms : _f_faq_add,
                url: 'productDetailService.deleteFaq',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_faq_store.reload();
					 Ext.getCmp('_f_faq_add').getForm().reset();
					_w_faq_add.hide();
                }
            });
		}
		
		function deleteImg() {
			AOS.ajax({
				forms : _f_img_add,
                url: 'productDetailService.deleteImg',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_img_store.reload();
					 Ext.getCmp('_f_img_add').getForm().reset();
					_w_img_add.hide();
                }
            });
		}
		
		
		
		//按钮列转换
		function fn_button_param_add(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="添加参数" class="cbtn" onclick="_w_param_add_show(\''+record.data.id+'\')" />';
		}
		
		function fn_button_faq_add(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="添加问答" class="cbtn" onclick="_w_faq_add_show(\''+record.data.id+'\')" />';
		}
		
		function fn_button_img_add(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="添加小图" class="cbtn" onclick="_w_img_add_show(\''+record.data.id+'\')" />';
		}
		
		
		
		function fn_button_param_edit(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="编辑" class="cbtn" onclick="_w_param_show()" />';
		}
		
		function fn_button_faq_edit(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="编辑" class="cbtn" onclick="_w_faq_show()" />';
		}
		
		function fn_button_img_edit(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="编辑" class="cbtn" onclick="_w_img_show()" />';
		}
		
		//按钮列转换
		function fn_button_param_del(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="删除" class="cbtn" onclick="_w_param_del(\''+record.data.id+'\')" />';
		}
		
		function fn_button_faq_del(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="删除" class="cbtn" onclick="_w_faq_del(\''+record.data.id+'\')" />';
		}
		
		function fn_button_img_del(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="删除" class="cbtn" onclick="_w_img_del(\''+record.data.id+'\')" />';
		}
		
		
		
		//上传图片
		function do_upload(setValueId){
			var form = pic_add_.getForm();
		    form.submit({
		       url: '/orisper/api/common/uploadPic.jhtml',
		       success: function(form, action) {
		    	   if(action.result.appcode == '-1'){
		        		AOS.tip(action.result.appmsg);
		        	}else{
		        		AOS.tip(action.result.appmsg); 
		        		AOS.setValue(setValueId, action.result.url);
		        	}
		       },
		       failure: function(form, action) {
		    	   AOS.tip("上传失败！");
		       }
		       
			}); 
		}
		
		
		
	</script>
</aos:onready>

<script type="text/javascript">
//param
function _w_param_show(){
	Ext.getCmp('_w_param').show();
}

function _w_param_add_show(product_id){
	AOS.setValue('_f_param_add.product_id', product_id);
	Ext.getCmp('_w_param_add').show();
}

function _w_param_del(id){
	var msg =  AOS.merge('确认要删除吗？');
	AOS.confirm(msg, function(btn){
		if(btn === 'cancel'){
			AOS.tip('删除操作被取消。');
			return;
		}
		AOS.ajax({
			url : 'productDetailService.deleteParam',
			params:{
				id: id
			},
			ok : function(data) {
				AOS.tip(data.appmsg);
				AOS.get('_g_params').getStore().reload();
			}
		});
	});
	
}




//faq
function _w_faq_add_show(product_id){
	AOS.setValue('_f_faq_add.product_id', product_id);
	Ext.getCmp('_w_faq_add').show();
}



function _w_faq_show(){
	Ext.getCmp('_w_faq').show();
}

function _w_faq_del(id){
	var msg =  AOS.merge('确认要删除吗？');
	AOS.confirm(msg, function(btn){
		if(btn === 'cancel'){
			AOS.tip('删除操作被取消。');
			return;
		}
		AOS.ajax({
			url : 'productDetailService.deleteFaq',
			params:{
				id: id
			},
			ok : function(data) {
				AOS.tip(data.appmsg);
				AOS.get('_g_faq').getStore().reload();
			}
		});
	});
}

//图片
function _w_img_add_show(product_id){
	AOS.setValue('_f_img_add.product_id', product_id);
	Ext.getCmp('_w_img_add').show();
}



function _w_img_show(){
	Ext.getCmp('_w_img').show();
}

function _w_img_del(id){
	var msg =  AOS.merge('确认要删除吗？');
	AOS.confirm(msg, function(btn){
		if(btn === 'cancel'){
			AOS.tip('删除操作被取消。');
			return;
		}
		AOS.ajax({
			url : 'productDetailService.deleteImg',
			params:{
				id: id
			},
			ok : function(data) {
				AOS.tip(data.appmsg);
				AOS.get('_g_img').getStore().reload();
			}
		});
	});
}





</script>